/**
 * 方法描述:
 * SJC 2018-9-17 19:50:32
 *
*/
$(function () {
    //最新公告
    $.ajax({
        url:application.contextPath+"/home/queryNewsByHome",
        type:"POST",
        dataType:"json",
        data:{},
        success:function (res) {
            if (res.isSuccess) {
                var newsList = res.data;
                if (newsList != null && newsList != "undefined") {
                    var $ta = $('<table class="table table-hover mb-0"></table>');
                    var th = '<thead>\n' +
                        '                    <tr>\n' +
                        '                    <th>标题</th>\n' +
                        '                    <th>类型</th>\n' +
                        '                    <th>时间</th>\n' +
                        '                    </tr>\n' +
                        '                    </thead>'
                    $ta.append(th);
                    var $tb = $('<tbody></tbody>');
                    $.each(newsList, function (i, obj) {
                        var trs = '<tr>\n' +
                            '   <td><a href=javascript:noticeDetail('+"'"+ obj.id+ "'" + ')>'+ obj.title + '</a></td>\n' +
                            '   <td><a href=javascript:noticeDetail('+"'"+ obj.id+ "'" + ')>' + obj.noticeType + '</a></td>\n' +
                            '   <td><a href=javascript:noticeDetail('+"'"+ obj.id+ "'" + ')>' + obj.createTime + '</a></td>\n' +
                            '</tr>'
                        $tb.append(trs);
                    })
                    $($ta).append($tb);
                    $("#news").append($ta)
                }
            }
        }
    });
    //最新课程
    // $.ajax({
    //     url:application.contextPath+"/home/queryNewsByHome",
    //     type:"POST",
    //     dataType:"json",
    //     data:{},
    //     success:function (res) {
    //         if (res.isSuccess) {
    //             var newsList = res.data;
    //             if (newsList != null && newsList != "undefined") {
    //                 var $ta = $('<table class="table table-hover mb-0"></table>');
    //                 var th = '<thead>\n' +
    //                     '                    <tr>\n' +
    //                     '                    <th>标题</th>\n' +
    //                     '                    <th>内容</th>\n' +
    //                     '                    <th>时间</th>\n' +
    //                     '                    </tr>\n' +
    //                     '                    </thead>'
    //                 $ta.append(th);
    //                 var $tb = $('<tbody></tbody>');
    //                 $.each(newsList, function (i, obj) {
    //                     var title = obj.content;
    //                     if (title.length > 40) {
    //                         title = title.substring(0, 39) + "...";
    //                     }
    //                     var trs = '<tr>\n' +
    //                         '   <td>' + obj.title + '</td>\n' +
    //                         '   <td>' + title + '</td>\n' +
    //                         '   <td>' + obj.createTime + '</td>\n' +
    //                         '</tr>'
    //                     $tb.append(trs);
    //                 })
    //                 $($ta).append($tb);
    //                 $("#lesson").append($ta)
    //             }
    //         }
    //     }
    // });
    // $.ajax({
    //     url:application.contextPath+"/home/queryNewsByHome",
    //     type:"POST",
    //     dataType:"json",
    //     data:{},
    //     success:function (res) {
    //         if (res.isSuccess) {
    //             var newsList = res.data;
    //             if (newsList != null && newsList != "undefined") {
    //                 var $ta = $('<table class="table table-hover mb-0"></table>');
    //                 var th = '<thead>\n' +
    //                     '                    <tr>\n' +
    //                     '                    <th>标题</th>\n' +
    //                     '                    <th>内容</th>\n' +
    //                     '                    <th>时间</th>\n' +
    //                     '                    </tr>\n' +
    //                     '                    </thead>'
    //                 $ta.append(th);
    //                 var $tb = $('<tbody></tbody>');
    //                 $.each(newsList, function (i, obj) {
    //                     var title = obj.content;
    //                     if(null!=title){
    //                         if (title.length > 40) {
    //                             title = title.substring(0, 39) + "...";
    //                         }
    //                     }
    //
    //                     var trs = '<tr>\n' +
    //                         '   <td>' + obj.title + '</td>\n' +
    //                         '   <td>' + title + '</td>\n' +
    //                         '   <td>' + obj.createTime + '</td>\n' +
    //                         '</tr>'
    //                     $tb.append(trs);
    //                 })
    //                 $($ta).append($tb);
    //                 $("#lesson").append($ta)
    //             }
    //         }
    //     }
    // });
    //消息
    $.ajax({
        url:application.contextPath+"/home/queryNoticeByHome",
        type:"POST",
        dataType:"json",
        data:{},
        success:function (res) {
            if(!res.isSuccess){
                 return;
            }else{
                //我发送的消息table填充
                var isendList = res.data.isendList;
                if (isendList != null && isendList != "undefined") {
                    var $ta = $('<table class="table table-hover mb-0"></table>');
                    var th = '<thead>\n' +
                        '                    <tr>\n' +
                        '                    <th>类型</th>\n' +
                        '                    <th>标题</th>\n' +
                        '                    <th>时间</th>\n' +
                        '                    </tr>\n' +
                        '                    </thead>'
                    $ta.append(th);
                    var $tb = $('<tbody></tbody>');
                    $.each(isendList, function (i, obj) {
                        var trs = '<tr>\n' +
                                    '   <td><a href=javascript:noticeDetail('+"'"+ obj.id+ "'" + ')>'+obj.cateName+'</a></td>\n' +
                                    '   <td><a href=javascript:noticeDetail('+"'"+ obj.id+ "'" + ')>'+obj.tit+'</a></td>\n' +
                                    '   <td><a href=javascript:noticeDetail('+"'"+ obj.id+ "'" + ')>'+obj.createTime+'</a></td>\n' +
                                    '</tr>'
                        $tb.append(trs);
                    })
                    $($ta).append($tb);
                    $("#isendMsg").append($ta)
                }

                var ireceivedList = res.data.ireceivedList;
                if (ireceivedList != null && ireceivedList != "undefined") {
                    var $ta = $('<table class="table table-hover mb-0"></table>');
                    var th = '<thead>\n' +
                        '                    <tr>\n' +
                        '                    <th>类型</th>\n' +
                        '                    <th>标题</th>\n' +
                        '                    <th>时间</th>\n' +
                        '                    </tr>\n' +
                        '                    </thead>'
                    $ta.append(th);
                    var $tb = $('<tbody></tbody>');
                    $.each(ireceivedList, function (i, obj) {
                        var trs = '<tr>\n' +
                            '   <td>'+obj.cateName+'</td>\n' +
                            '   <td>'+obj.tit+'</td>\n' +
                            '   <td>'+obj.createTime+'</td>\n' +
                            '</tr>'
                        $tb.append(trs);
                    })
                    $($ta).append($tb);
                    $("#ireceivedMsg").append($($ta))
                }
                var scount = res.data.sendCount;
                $("#sendCount").text(scount)
                var rcount = res.data.receivedCount;
                $("#recivedCount").text(rcount)
            }

        }
    });
    
})

function noticeDetail(id){
    loadUtil = new Load($);
    loadUtil.load({
        container: '#homeContent',
        url: application.contextPath + "/notice/showNoticeInfoTiny?ntId="+id
    });
}